{template '../../header'}
{template '../../left'}

<div class="card">
    <div class="card-header">
        文章管理
    </div>
    <div class="card-body">
        <div class="row mb-2">
            <div class="col-12">
                <form method="get" class="form-row">
                    <div class="form-group col-2">
                        <label>栏目</label>
                        <select class="form-control form-control-sm" id="filter_column_id" name="filter_column_id">
                            <option value='0'>--请选择--</option>
                            {loop $columns $row}
                            <option value="{$row['id']}" {:$filter_column_id == $row['id']?'selected':''}>{$row['title']}</option>
                            {/loop}
                        </select>
                    </div>
                    <div class="form-group col-2">
                        <label>标题</label>
                        <input type="text" id="filter_title" name="filter_title" value="{$filter_title}" class="form-control form-control-sm" />
                    </div>
                    <div class="form-group col-1">
                        <label>公告板推荐</label>
                        <select name="filter_top" class="form-control form-control-sm">
                            <option value="0">--请选择--</option>
                            <option value="1" {if $filter_top == 1}selected{/if}>已推荐</option>
                            <option value="-1" {if $filter_top == -1}selected{/if}>未推荐</option>
                        </select>
                    </div>
                    <div class="form-group col-1">
                        <label>栏目推荐</label>
                        <select name="filter_hot" class="form-control form-control-sm">
                            <option value="0">--请选择--</option>
                            <option value="1" {if $filter_hot == 1}selected{/if}>已推荐</option>
                            <option value="-1" {if $filter_hot == -1}selected{/if}>未推荐</option>
                        </select>
                    </div>
                    <div class="form-group col-2">
                        <label>起始时间</label>
                        <input type="text" id="filter_begin" name="filter_begin" value="{$filter_begin}" class="form-control form-control-sm datepicker" />
                    </div>
                    <div class="form-group col-2">
                        <label>结束时间</label>
                        <input type="text" id="filter_end" name="filter_end" value="{$filter_end}" class="form-control form-control-sm datepicker" />
                    </div>
                    <div class="form-group col-1">
                        <label>搜索</label>
                        <div class="form-control-static">
                            <button class="btn btn-success btn-sm" type="submit" name="do" value="search"><i class="fa fa-search"></i> 搜索</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="row mb-3">
            <div class="col-12">
                <button type="button" class="btn btn-danger btn-sm" onclick="deleteAll();"><i class="fa fa-trash-o"></i> 删除</button>
                <a href="/admin/cms/article/edit" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> 添加</a>
            </div>
        </div>
        <form method="post">
            <table class="table table-sm table-striped table-hover">
                <thead>
                <th style="width: 80px;">
                    <label for="check_all">
                        <input type="checkbox" id="check_all" />&nbsp;全选
                    </label>
                </th>
                <th>
                    标题
                </th>
                <th>
                    栏目
                </th>
                <th>
                    类型
                </th>
                <th>
                    公告板推荐
                    <span class="badge badge-pill badge-info" 
                          data-toggle="tooltip" 
                          title="设置后推荐到公告板，并按顺序展示">?</span>
                </th>
                <th>
                    栏目推荐
                    <span class="badge badge-pill badge-info" 
                          data-toggle="tooltip" 
                          title="设置后推荐到首页分栏目列表，以及列表页和详情页右侧推荐栏，并按顺序展示">?</span>
                </th>
                <th>
                    状态
                </th>
                <th>
                    修改时间
                </th>
                <th>
                    评论
                </th>
                <th>
                    编辑
                </th>
                <th>
                    删除
                </th>
                </thead>
                <tbody>
                    {loop $rows $row}
                    <tr>
                        <td>
                            <label for="check_{$row['id']}">
                                <input type="checkbox" id="check_{$row['id']}" name="checks[]" value="{$row['id']}" />&nbsp;{$row['id']}
                            </label>
                        </td>
                        <td>
                            <a href="/cms/article/page/id/{$row['id']}" target="_blank">{$row['title']}</a>
                        </td>
                        <td>
                            {$row['column_title']}
                        </td>
                        <td>
                            {$row['type_title']}
                        </td>
                        <td>
                            <input type="text" class="form-control form-control-sm" size="2" name="tops[{$row['id']}]" value="{$row['top']}" />
                        </td>
                        <td>
                            <input type="text" class="form-control form-control-sm" size="2" name="hots[{$row['id']}]" value="{$row['hot']}" />
                        </td>
                        <td>
                            {$row['state_title']}
                        </td>
                        <td>
                            {$row['update_time']}
                        </td>
                        <td>
                            <a class="btn btn-info btn-sm" href="/admin/cms/article/reply/index?article_id={$row['id']}"><i class="fa fa-list-ul"></i></a>
                        </td>
                        <td>
                            <a class="btn btn-primary btn-sm" href="/admin/cms/article/edit?id={$row['id']}"><i class="fa fa-edit"></i></a>
                        </td>
                        <td>
                            <button type="button" class="btn btn-danger btn-sm"  onclick="confirm('你确定要删除吗？') && (location.href='/admin/cms/article/remove?id={$row['id']}')"><i class="fa fa-trash-o"></i></button>
                        </td>
                    </tr>
                    {/loop}
                </tbody>
            </table>
            <div class="row mb-3">
                <div class="col-12">
                    <button type="submit" class="btn btn-primary btn-sm mr-3" name="do" value="top_sort"><i class="fa fa-sort-amount-desc"></i> 保存公告板推荐排序</button>
                    <button type="submit" class="btn btn-success btn-sm" name="do" value="hot_sort"><i class="fa fa-sort-amount-desc"></i> 保存栏目推荐排序</button>
                </div>
            </div>
        </form>
        {template '../../page'}
    </div>
</div>

<script type="text/javascript">

    $(function () {
        $("#check_all").click(function () {
            $('input[name="checks[]"]').prop('checked', this.checked);
        });
    });

    function deleteAll() {

        if (confirm("您确定要删除选定的项目吗？")) {

            var ret = [];

            var ids = new Array();

            $('input[name="checks[]"]:checked').each(function () {
                val = $(this).val();
                ids.push(val);
            });

            if (ids.length == 0) {
                alert('请选择要删除的公告');
                return false;
            }

            ajax({
                url: "/admin/cms/article/index?do=deleteall",
                method: 'post',
                data: {ids: ids},
                success: function (ret) {
                    if (ret.code == 1) {
                        alert('操作成功');
                        location.reload();
                    } else {
                        alert(ret.msg);
                    }
                }
            });
        }
    }
</script>

{template '../../footer'}   